package niuke;

import java.util.Scanner;

public class 分苹果 {

    static int n;
    static int[] apple;
    static int result = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        apple = new int[n];
        for(int i=0;i<n;i++){
            apple[i] = scanner.nextInt();
        }
        int sum = 0;
        int ave;
        //求和
        for(int i=0;i<n;i++){
            sum += apple[i];
        }
        //判断是否除尽
        if(sum%n != 0){
            System.out.println(-1);
            return;
        }
        ave = sum/n;

        for(int i=0;i<apple.length;i++){
            if(apple[i]<ave){
                if((ave-apple[i])%2 == 0){
                    result = result + (ave-apple[i])/2;
                }
                else {
                    System.out.println(-1);
                    return;
                }
            }
            else if(apple[i]>ave && (apple[i] - ave)%2 != 0){
                System.out.println(-1);
                return;
            }
        }
        System.out.println(result);
    }
}
